<!DOCTYPE html>
<html>
<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
<!--引入消息提示插件-->
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>

    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem("user"));
            // 当前页变量  / 手机是滑动查询下一页的
            var currentPage = 1;
            // 总页数
            var pages;
            //存储游记的数组
            var travelArr = []; // js中数组是变长的,很方便做数组拼接
            function query() {
                // 获取所有的游记
                $.get('/travels', {currentPage: currentPage}, function (data) {
                    // 把第二个数组合并带第一个数组中
                    $.merge(travelArr, data.list);
                    /*先将数组封装成一个json字符串 ,
                    给他一个list属性名,在渲染数据的时候给list拿去循环渲染*/
                    var json = {
                        list: travelArr
                    }
                    // 渲染数据
                    $("#allTravels").renderValues(json, {
                        // 对a连接做处理,子啊地址栏上拼接一个当前游记的id,
                        getHref: function (item, value) {
                           $(item).attr('href', '/travelContent.html?id=' + value);
                        },
                        getHeadImgHref:function (item,value) {
                            var url = $(item).data('href');
                            $(item).attr("href", url + value);
                        }
                    });
                    // 获取总页数
                    pages = data.pages;
                })
                // 每次查询加一页
                currentPage = currentPage + 1;
            }

            // 调用方法 默认查询第一页
            query();
            //给window绑定事件
            $(window).scroll(function () {
                if ($(window).height() + $(document).scrollTop()+1 >= $(document).height()) {
                    //console.log("进行分页....");
                    // 判断是否到最后一页 / 如果大于最后一页就不发送请求了
                    if (currentPage <= pages) {
                        query();
                    } else {
                        // 已经到最后了就提示用户已经到底了(引入插件)
                        $(document).dialog({
                            type: "notice",  // 好像是设置样式
                            content: "<span class='info-text'>没有更多了!</span>", // 显示的文字
                            autoClose: 1000 // 多久后关闭
                        })
                    }
                }
            });

            // 每月冠军游记
            $.get("/travels/commends", {type: 2, pageSize: 3}, function (data) {
                $("#travelsCommends").renderValues(data, {
                    getHref: function (item, value) {
                        $(item).attr("href", "/travelContent.html?id=" + value);
                    }
                });
                //渲染完数据为第一给div设置active
                $(".carousel-item:first").addClass("active");
            })

        })
    </script>

</head>

<body>

<div class="search-head operationTop">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜游记">
            </div>
        </div>
    </div>
</div>
<div class="search-head" style="height: 48px;background: white;">
</div>
<div class="container">
    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div id="travelsCommends" class="carousel-inner">
            <div render-loop="list">
                <div class="carousel-item">
                    <div class="border commend">
                        <a render-fun="getHref" render-key="list.travel_id">
                            <img render-src="list.coverUrl" width="100%" height="200px">
                            <h1 render-html="list.title"> 骨灰级成都吃货地图</h1>
                            <small render-html="list.subTitle">成都成都</small>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>

<div class="container">
    <h6>全部游记</h6>
    <div id="allTravels">
        <!--render-loop 意思是要循环遍历的数据是list-->
        <div class="list" render-loop="list">
            <div class="row detail">
                <div class="col">
                    <!--a标签的渲染-->
                    <a render-fun="getHref" render-key="list.id">
                        <!--游记标题-->
                        <h4 render-html="list.title"></h4>
                    </a>
                    <p>
                        <a data-href="userProfiles.html?id=" render-fun="getHeadImgHref" render-key="list.author.id">
                            <!--用户头像-->
                            <img class="rounded-circle head-img"
                                 render-src="list.author.headImgUrl">
                            <span  render-html="list.author.nickName"></span>
                        </a> 在
                        <span class="addr" render-html="list.place.name"></span>

                    </p>
                    <p>
                        <i class="fa fa-eye fa-fw"></i>
                        <span>0</span>
                        <i class="fa fa-commenting fa-fw"></i>
                        <span>0</span>
                    </p>
                </div>
                <div class="col bigimg">
                    <a render-fun="getHref" render-key="list.id">
                        <!--游记的封面-->
                        <img render-src="list.coverUrl">
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>


</body>

</html>